<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt"  prefix="fmt"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>查询商品列表</title>
<script type="text/javascript">
	function createXMLHttpRequest() {
	    try {
	        return new XMLHttpRequest();
	    } catch(e) {
	        try {
	            return new ActiveXObject("Msxml2.XMLHTTP");
	        } catch(e) {
	            try {
	                return new ActiveXObject("Microsoft.XMLHTTP");
	            } catch(e) {
	                alter("浏览器不兼容！");
	                throw e;
	            }
	        }
	    }
	}   
	window.onload = function() {
		var btn = document.getElementById("btn");
		btn.onclick = function() {
			var xmlHttp = createXMLHttpRequest();
			xmlHttp.open("POST","${pageContext.request.contextPath }/item/itemjson.action", true);
			xmlHttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
			xmlHttp.send('{"id": 1,"name": "测试商品","price": 99.9,"detail": "测试商品描述","pic": "123456.jpg"}');
			xmlHttp.onreadystatechange = function() {
                if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
                      var content = xmlHttp.responseText;
                      var h3 = document.getElementById("h3");
                      h3.innerHTML = content;
                }
          };
		};
	};
</script>
</head>
<body> 

<input type="submit" id="btn" value="提交"/>
<h3 id="h3"></h3>

</body>

</html>